<?php

namespace slinks\common\matcher\text;

use slinks\common\matcher\IMatcher;

/**
 * This matcher matches Strings against a regular expression pattern. 
 * It the $canidate is not a string it will be cast to one. 
 * 
 * @author Navid Mitchell
 *
 */
class StringRegExMatcher implements IMatcher {

    private $pattern;

    /**
     * Construct a new RegExStringMatcher with the given regular expression pattern. 
     * @param string $pattern
     */
    function __construct($pattern) {
        $this->pattern = $pattern;
    }

    /**
     * Called to determine if a given canidate "Matches" the given regular expression pattern. 
     * 
     * @param string $canidate
     * @return bool true if the canidate "Matches" false if not.
     */
    public function matches($canidate) {
        $val = (string) $canidate;
        return preg_match($this->pattern, $val);
    }

}